// +----------------------------------------------------------------------
// | BossHongshi [鸿时互娱管理系统]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.hongshihuyu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wgh
// +----------------------------------------------------------------------
const fly=require("flyio")
module.exports = class extends think.cmswing.center {
  /**
     * index action
     * @return {Promise} []
     */
  async indexAction() {
	//cmd=pay&uid=23&agent_id=490480&id=321&amount=50.00&type=card&qty=1
	  console.log('app 支付开始---------:');
	
	const cmd = this.get('cmd') || '';
	const uid = this.get('uid') || '';//玩家游戏ID
	const agentid = this.get('agent_id') || '';//玩家从属的代理ID 
	const id = this.get('id') || '';//商品ID 
	const amount = this.get('amount') || '';//商品价格 
	const type = this.get('type') || '';//商品类型
	const qty = this.get('qty') || 1;//购买数量
	
	if(think.isEmpty(uid)){
		let  errmsg = '游戏ID为空！';
		this.assign('errmsg', errmsg);
		if (this.isMobile) {
		      return this.display(this.mtpl());
		    } else {
		      return this.display();
		}
	}
	
	this.meta_title = '商品支付';// 标题1
	
	// console.log('home/pay.js---------cmd:'+cmd);
	// console.log('home/pay.js---------uid:'+uid);
	// console.log('home/pay.js---------agentid:'+agentid);
	// console.log('home/pay.js---------goodid:'+id);
	// console.log('home/pay.js---------amount:'+amount);
	// console.log('home/pay.js---------type:'+type);
	// console.log('home/pay.js---------qty:'+qty);
	
	const url = 'http://47.97.119.70:5166/GameSupport/dn?cmd=getPlayerByUid&uid='+uid+'&sign=password';
	
	console.log('getPlayerByUid url---------:'+url);
	
    fly.config.timeout=10000;
	fly.config.parseJson=true;
	fly.interceptors.response.use(
		    (response) => {
		        //只将请求结果的data字段返回
		        return response.data
		    },
		    (err) => {
		        //发生网络错误后会走到这里
		        //return Promise.resolve("ssss")
		    }
    )
	  
	let ret = await fly.get(url).catch(() => false);
	//{\"data\":{\"command\":\"getPlayerByUid\",\"info\":{\"agentId\":0,\"cardNum\":500,\"goldNum\":10000,\"nickname\":\"雅訫\",\"referrer_uid\":0,\"uid\":334020},\"msg\":\"查询成功\",\"originCommand\":\"getPlayerByUid\",\"result\":0},\"uid\":334020}"

	console.log('ret ---------:'+ret);
//	console.log('ret.data---------:'+JSON.stringify(ret.data));
	let retdata = (ret === false?null:JSON.parse(ret));
	
	if(retdata!=null&&retdata.data.result==0){
			if(!think.isEmpty(retdata.data.info.uid)&&
					retdata.data.info.uid!=uid){
				let  errmsg = '游戏ID不合法！';
				this.assign('errmsg', errmsg);
				if (this.isMobile) {
				      return this.display(this.mtpl());
				    } else {
				      return this.display();
				}
			}
		
		
			if(!think.isEmpty(retdata.data.info.referrer_uid)){
				if(think.isEmpty(agentid)){
					let errmsg = '代理ID为空！';
					this.assign('errmsg', errmsg);
					if (this.isMobile) {
					      return this.display(this.mtpl());
					    } else {
					      return this.display();
					 }
				}else{
					if(retdata.data.info.referrer_uid!=0&&retdata.data.info.referrer_uid!=agentid){
						let errmsg = '代理ID不合法！';
						this.assign('errmsg', errmsg);
						if (this.isMobile) {
						      return this.display(this.mtpl());
						    } else {
						      return this.display();
						 }
					}
				}
			}
				
    }else {
    	let errmsg = '游戏ID不存在！';
    	this.assign('errmsg', errmsg);
    	if (this.isMobile) {
    	      return this.display(this.mtpl());
    	} else {
    	    return this.display();
    	}
    }
	
	// 应付金额
    const parr = [];
    const isgoods = [];
    let order_amount;// 订单金额
    let real_amount;// 商品参与获得的价格
    let data = {};
    
    //const member = await this.model('member').where({id:this.user.uid}).field('groupid,area').find();
    //const ratio = await this.model('cmswing/rebate').getrebate(member.groupid,member.area);
    
    let goods = await this.model('document').find(id);
    if(!think.isEmpty(goods)){
    	console.log('home/pay goods---------存在:'+qty);
    	let goodprice= get_price(goods.price, 1)
    	let goods_price = Number(goodprice)*Number(qty);
    	console.log('goods_price---------:'+goods_price);
    	//parr.push(goods_price);
    	goods.goods_price=goods_price;
    	goods.goods_nums=qty;
    	goods.goods_no = await this.model('document_shop').where({id:id}).getField('goods_no', true);
    	
    	let prom_goods = {};
    	prom_goods.id=goods.id;
    	prom_goods.uid=uid;
    	prom_goods.product_id=goods.id;
    	prom_goods.qty=qty;
    	prom_goods.type=goods.type;
    	prom_goods.price=goods_price;
    	prom_goods.title=goods.title;
    	prom_goods.unit_price=goods.goods_price;
    	prom_goods.pic= await get_pic(goods.pics, 1, 100, 100);
    	prom_goods.url=get_url(goods.name, goods.id);
    	prom_goods.weight=0;
    	prom_goods.fare='';
    	goods.prom_goods = prom_goods;
    	isgoods.push(goods);
    	
    	//real_amount = eval(parr.join('+'));
    	real_amount = goods_price;
    	console.log('real_amount---------:'+real_amount);
        // 用户
        data.user_id = uid;
        // 生成订单编号//todo
        
        data.order_no = await this.model('cmswing/order').orderid(uid,'03');
        
        data.real_amount = real_amount;

        // 支付状态 pay_stayus 0:未付款 ,1:已付款
        data.pay_status = 0;
        // 订单状态 status 2:等待审核，3:已审核
        data.status = 2;
        // 发货状态 delivery_status 0:未发货，1:已发货
        data.delivery_status = 0;
        // 订单创建时间 create_time
        data.create_time = new Date().valueOf();
        // 客户订单备注
        // TODO
        // console.log(real_amount);
        order_amount = Number(data.real_amount);
        data.order_amount = order_amount;
        data.binding=agentid;
        data.origin=1;
        // 生成订单
        const order_id = await this.model('order').add(data);
        
        // 储存商品
        const ngoods = [];
        for (const goods of isgoods) {
          const newgoods = {};
          newgoods.order_id = order_id;
          newgoods.goods_id = goods.id;
          newgoods.goods_price = goods.goods_price;
          newgoods.goods_real_price = goods.goods_price;
          newgoods.goods_nums = goods.goods_nums;
          newgoods.prom_goods = JSON.stringify(goods.prom_goods);
          newgoods.goods_no = goods.goods_no;
          ngoods.push(newgoods);
        }
        
        await this.model('order_goods').addMany(ngoods);
        
        // 订单信息
        const order = await this.model('order').where({pay_status: 0, user_id:uid}).find(order_id);
        if (think.isEmpty(order)) {
          const error = this.controller('cmswing/error');
          return error.noAction('订单不存在或者已经支付！');
        }
        order.end_time = date_from(order.create_time + (Number(this.config('setup.ORDER_DELAY')) * 60000));
        this.assign('order', order);
    }else{
    	console.log('home/pay goods---------2不存在:');
        return this.redirect('/cmswing/error/no');
    }

    // 减少订单中商品的库存
    //await this.model('cmswing/order').stock(order_id, true);
    
    // 判断浏览客户端
    let map;
    if (this.isMobile) {
        map = {
          type: 6,
          status: 1,
          agent:'yinfupay'
        };
        if (!this.isweixin) {
          map.channel = ['!=', 'wx_pub'];
        }
      } else {
        map = {
          type: 1,
          status: 1
        };
    }
    
    const paylist = await this.model('pingxx').where(map).order('sort ASC').select();
    this.assign('paylist', paylist);
    this.assign('setp', 3);
    
    this.keywords = this.config('setup.WEB_SITE_KEYWORD') ? this.config('setup.WEB_SITE_KEYWORD') : '';// seo关键词
    this.description = this.config('setup.WEB_SITE_DESCRIPTION') ? this.config('setup.WEB_SITE_DESCRIPTION') : '';// seo描述
    // 判断浏览客户端
    if (this.isMobile) {
      return this.display(this.mtpl());
    } else {
      return this.display();
    }
  }
  
//支付
  async payAction() {
    if (this.isAjax('post')) {
      let payment;
      let pay;
      let charges;
      const post = this.post();
      let data = post;
      // 获取订单信息
      const order = await this.model('order').where({pay_status:0}).find(post.order_id);
      if (think.isEmpty(order)) {
        return this.fail('订单不存在！');
      }
      
      // 支付日志
      const receiving = {
        order_id: post.order_id,
        user_id: order.user_id,
        amount: order.order_amount,
        create_time: new Date().getTime(),
        payment_time: new Date().getTime(),
        doc_type: 0,
        payment_id: post.payment,
        pay_status: 0
      };

      // 100预付款支付
      if (post.payment == 100) {
        // 先检查下用户余额
        const balance = await this.model('member').where({user_id: this.user.uid}).getField('amount', true);
        if (Number(balance) < Number(order.order_amount)) {
          return this.fail('您余额不足，请充值，或者选择其他支付方式！');
        } else {
          // 扣款
          const decrement = this.model('member').where({user_id: this.user.uid}).decrement('amount', Number(order.order_amount));
          if (decrement) {
            // 扣款成功改变订单状态
            await this.model('order').where({order_no: order.order_no}).update({status: 3, pay_status: 1});
            // 扣款成功后插入日志
            const log = {
              admin_id: 0,
              user_id: this.user.uid,
              type: 2,
              time: new Date().valueOf(),
              amount: (0 - Number(order.order_amount)),
              amount_log: await this.model('member').where({id: this.user.uid}).getField('amount', true),
              note: `${await get_nickname(this.user.uid)} 通过余额支付方式进行商品购买,订单编号：${order.order_no}`
            };
            await this.model('balance_log').add(log);
            receiving.pay_status = 1;
            await this.model('doc_receiving').add(receiving);
            const url = `/center/pay/payres/?c_o_id=${post.order_id}`;
            return this.success({name: '支付订单对接成功，正在转跳！', url: url});
          } else {
            return this.fail('您没有要支付的订单');
          }
        }
      }
      if (post.payment == 1001) {
        const url = `/center/pay/payres/?c_o_id=${post.order_id}`;
        return this.success({name: '支付订单对接成功，正在转跳！', url: url});
      }
      // 1001货到付款
      if (think.isEmpty(order)) {
        return this.fail('您没有要支付的订单');
      } else {
        // 判断是否已经绑定pingxx_id,如果已绑定查询pingxx订单直接支付。防止订单重复生成。
        // console.log(order.id);
        if (think.isEmpty(order.pingxx_id)) {
        
          // 获取渠道
          
//          const parter = this.config('setup.KAIRUI_APP_ID');// '1884'
//      	  const key = this.config('setup.KAIRUI_LIVE_SECRET_KEY');//'bb3cb208045c4a289c305e4cc7d1d7db'
//      	  const serverUrl = this.config('setup.KAIRUI_SERVER_URL');// 'http://g.788xw.com/bank/'
//      	  const callbackUrl = this.config('setup.KAIRUI_APP_CALLBACK_URL');//'http://www.hongshihuyu.com/pay/notify'
//      	  const hrefbackUrl = this.config('setup.KAIRUI_APP_HREFBACK_URL');//'http://www.hongshihuyu.com/pay/result?orderid=022018093006908aba88'
          const parter = '200073';
          const key = '1o4ur5fdzbzppr3nndgvdf1ptv7dwevn';
          const serverUrl = 'http://www.yinfupay.net/Pay_Index.html';
          const callbackUrl = 'http://www.hongshihuyu.com/pay/notify';
          const hrefbackUrl = 'http://www.hongshihuyu.com/pay/result';
          const channel = await this.model('pingxx').where({id:data.payment}).getField('channel', true);//'6001'
            
      	  var money=order.order_amount;
          var orderId=order.order_no;
          var payerIp="";
		  var attach = '';
          for (var i = 0; i < 8; i++) {
             attach += Math.floor(Math.random() * 10);
          }
          //var signStr='parter='+parter+'&type='+channel+'&value='+money+'&orderid='+orderId+'&callbackurl='+callbackUrl+key;
          var pay_applydate=this.moment(new Date().valueOf()).format('YYYY-MM-DD HH:mm:ss')
		  var signStr='pay_amount='+money+'&pay_applydate='+pay_applydate+'&pay_bankcode='+channel+'&pay_callbackurl='+hrefbackUrl+'/'+orderId+'&pay_memberid='+parter+'&pay_notifyurl='+callbackUrl+'&pay_orderid='+orderId+'&key='+key;
			console.log('signStr---------:'+signStr);
			signStr=think.md5(signStr);
			console.log('signStr md5---------:'+signStr);
			signStr=signStr.toUpperCase();
			console.log('signStr toUpperCase---------:'+signStr);
            data.parter=parter;
            data.channel=channel;
            data.money=money;
            data.orderId=orderId;
            data.callbackurl=callbackUrl;
            data.hrefbackurl=hrefbackUrl+'/'+orderId;
            data.key=key;
            data.serverUrl=serverUrl;
            data.payerIp=payerIp;
            data.attach =attach;
			data.pay_applydate=pay_applydate;
			data.productname = "流量点卡";
            data.sign = signStr;
        } 
        // console.log(charges);
        if (data) {
          // 更新订单的sign取值
          console.log('data---------:'+JSON.stringify(data));
          
          // 更新订单的支付方式,sign,attach
          await this.model('order').where({id: order.id}).update({payment: data.payment,sign:data.sign,attach:data.attach});
          await this.model('doc_receiving').add(receiving);
          return this.success({name: '支付订单对接成功，正在转跳！', data: data});
        } else {
          return this.fail('调用接口失败！');
        }
      }
    } else {
    	return this.fail('调用接口失败！');
    }
  }
  
  // app端支付回调
  async notifyAction() {
    const code = this.post();
    console.log('app端支付回调code--1:'+JSON.stringify(code));
//  支付接口回掉
    const order = await this.model('order').where({order_no:code.orderid}).find();
    if(!think.isEmpty(order)){
      console.log('app端支付回调code.attach--:'+code.attach);
      console.log('app端支付回调order.attach--:'+order.attach);
      if(code.attach==order.attach){
        if(code.returncode=='00'){
        console.log('app端支付回调order.pay_status--:'+order.pay_status);
        if (order.pay_status == 0) {
//    	console.log('app端支付回调order.pay_status--2:'+order.pay_status);
        // 支付成功改变订单状态 code.systime

    	//var time_paid = (new Date(code.systime)).getTime();
    	//var completiontime = (new Date(code.completiontime)).getTime();
		var time_paid = (new Date()).getTime();
    	var completiontime = (new Date()).getTime();
        const update = await this.model('order').where({order_no:code.orderid}).update({status:4,pay_status: 1, notify_remark:"支付成功",pay_time:time_paid,completion_time:completiontime,pingxx_id:code.transaction_id});
        console.log('app端支付回调update--1 成功:'+update);
        if (update) {
          console.log('app端支付回调order.type--:'+order.type);
          if (order.type == 1) {
            await this.model('member').where({id: order.user_id}).increment('amount', order.order_amount);
            // 充值成功后插入日志
            const log = {
              admin_id: 0,
              user_id: order.user_id,
              type: 2,
              time: new Date().valueOf(),
              amount: Number(order.order_amount),
              amount_log: await this.model('member').where({id: order.user_id}).getField('amount', true),
              note: `${await get_nickname(order.user_id)} 通过[${await this.model('pingxx').where({id: order.payment}).getField('title', true)}]支付方式进行充值,订单编号：${order.order_no}`
            };
            await this.model('balance_log').add(log);
          }else if(order.type == 0){
        	  fly.config.timeout=10000;
              fly.config.parseJson=true;
              fly.interceptors.response.use(
		      (response) => {
			   //只将请求结果的data字段返回
			   return response.data
		      },
		      (err) => {
		       //发生网络错误后会走到这里
			    //return Promise.resolve("ssss")
		       }
	         )
        	  let ordergood = await this.model('order_goods').where({order_id:order.id}).field('goods_no,goods_nums').find();
//        	  console.log('app端支付回调 ordergood--1:'+JSON.stringify(ordergood));
        	  if (!think.isEmpty(ordergood)) {
        		  if(!think.isEmpty(ordergood.goods_no)){
        			  console.log('app端支付回调 ordergood.goods_no--:'+ordergood.goods_no);
        			  const goodnos = ordergood.goods_no.split('_');
    				  if(goodnos.length>1){
    					  var url ='http://47.97.119.70:5166/GameSupport/dn?cmd=';
    					  if(goodnos[0]=='card'){
    						  url+='addCard';
    						  
    					  }else if(goodnos[0]=='coin'){
    						  url+='addGold';
    					  }
    					  console.log('游戏app端开始充值!');
    				      url+='&uid='+order.user_id+'&value='+(Number(goodnos[1])*Number(ordergood.goods_nums))+'&sign=password';
    				      console.log('app端充值--url:'+url);
                  
                          let ret = await fly.get(url).catch(() => false);
	                      console.log('bindByUid ret------------------:'+ret);
                          let retdata = (ret === false?null:JSON.parse(ret));
                        
    				      //let ret = await fly.get(url);
    					  //let retdata = JSON.parse(ret.data);
    					  
    					  if(retdata.data.result==0){
                            console.log('游戏app端交易成功!');
                            await this.model('order').where({order_no:code.orderid}).update({delivery_status:1});
                            console.log('更新支付订单充值成功!');
    						  //order.pay_status
    						  console.log(order.binding+' 充值分润 代理id-----:'+order.binding);
                              if(!think.isEmpty(order.binding)){
                            	  console.log(order.order_no+' 充值分润 获取规则rebate 开始-----!');
                            	  console.log(order.order_no+' 充值分润 获取规则rebate goodnos[0] -----:'+goodnos[0]);
                            	  const rebate = await this.model('rebate').where({rebate_no:'buy_'+goodnos[0],is_default:1}).find();
                            	  console.log(order.order_no+' 充值分润 获取规则  rebate-----!'+JSON.stringify(rebate));
                            	  if(!think.isEmpty(rebate)){
           				        	console.log(order.order_no+' 充值分润 获取规则rebate 成功-----!');
           				        	console.log(order.order_no+' 充值分润 获取代理 开始-----!');
           				        	const member = await this.model('member').where({proxy_id:order.binding}).find();
           				        	if(!think.isEmpty(member)&&member.game_id!=order.user_id){
           				        		console.log(order.order_no+' 充值分润 获取代理 成功-----!');
           				        	    //分润
           				        		console.log(order.order_no+' 充值分润开始-----!');
           				        		//来源ID，如果来源为订单，则为order表的id，如果来源为消耗，则为消耗记录id
           				        		//0:订单充卡，1:订单充币,2:消耗房卡,3:消耗金币
           				        		
           				        		if(!think.isEmpty(rebate.first_ratio)){
           				        			console.log(order.order_no+' 充值分润第一级'+member.id+'开始-----!');
           				        			let fp_amount =Number(order.order_amount)*Number(rebate.first_ratio)/100;
           				        			const fplog = {
                         			                user_id:member.id,
                         			                proxy_id:member.proxy_id,
                         			                type:(goodnos[0]=='card'?0:1),
                         			                amount: Number(fp_amount),
                                 			        amount_log:Number(member.amount)+Number(fp_amount),
                                 			        status:0,
                                 			        origin_id:order.id,
                         			                create_time: new Date().valueOf(),
                         			                act_id:order.user_id,
                         			                note: `${member.proxy_id} 通过 [${order.user_id}]购买${goodnos[0]}分润,订单编号：${order.order_no}`
                         			             };
                         			        await this.model('profit_log').add(fplog);
                         			       console.log(order.order_no+' 充值分润第一级'+member.id+'结束-----!');
                         			       if(!think.isEmpty(rebate.second_ratio)){
              				        			let sp_amount =Number(order.order_amount)*Number(rebate.second_ratio)/100;
              				        			const smember = await this.model('member').where({proxy_id:member.ia_uname}).find();
              				        			if(!think.isEmpty(smember)&&smember.is_admin!=1){
              				        				console.log(order.order_no+' 充值分润第二级'+smember.id+'开始-----!');
              				        				const splog = {
                                			                user_id:smember.id,
                                			                proxy_id:smember.proxy_id,
                                			                type:goodnos[0]=='card'?0:1,
                                			                amount: Number(sp_amount),
                                        			        amount_log:Number(smember.amount)+Number(sp_amount),
                                        			        status:0,
                                        			        origin_id:order.id,
                                			                create_time: new Date().valueOf(),
                                			                act_id:member.id,
                                			                note: `${smember.proxy_id} 通过 [${order.user_id}]购买${goodnos[0]=='card'?房卡:金币}分润,订单编号：${order.order_no}`
                                			        };
                                			        await this.model('profit_log').add(splog);
                                			        console.log(order.order_no+' 充值分润第二级'+smember.id+'结束-----!');
              				        			}
                            			        
                            			        if(!think.isEmpty(rebate.three_ratio)){
                            			        	let tp_amount =Number(order.order_amount)*Number(rebate.three_ratio)/100;
                  				        			const tmember = await this.model('member').where({proxy_id:smember.ia_uname}).find();
                  				        			if(!think.isEmpty(tmember)&&tmember.is_admin!=1){
                  				        				console.log(order.order_no+' 充值分润第三级'+tmember.id+'开始-----!');
                  				        				const tplog = {
                                    			                user_id:tmember.id,
                                    			                proxy_id:tmember.proxy_id,
                                    			                type:goodnos[0]=='card'?0:1,
                                    			                amount: Number(tp_amount),
                                            			        amount_log:Number(tmember.amount)+Number(tp_amount),
                                            			        status:0,
                                            			        origin_id:order.id,
                                    			                create_time: new Date().valueOf(),
                                    			                act_id:smember.id,
                                    			                note: `${tmember.proxy_id} 通过 [${order.user_id}]购买${goodnos[0]=='card'?房卡:金币}分润,订单编号：${order.order_no}`
                                    			        };
                                    			        await this.model('profit_log').add(tplog);
                                    			        console.log(order.order_no+' 充值分润第三级'+tmember.id+'结束-----!');
                  				        			}
                  				        		}
              				        		}
              				        		
           				        		}
           				        		console.log(order.order_no+' 充值分润结束-----!');
           				        	}
           						}
    						}  
    					  }else{
                               await this.model('order').where({order_no:code.orderid}).update({delivery_status:-1});
                               console.log('更新支付订单充值失败!');
    					  	  return this.fail('游戏app端充值失败！');
    					  } 
    				  }
        		  }
        	  }
        	  
        	  // 充值成功后插入日志
        	  //0:账户充值，1:提现,2:订单,3:充卡,4:充币,5:返利
              const log = {
                admin_id: 0,
                user_id: order.user_id,
                type: 2,
                time: new Date().valueOf(),
                amount: Number(order.order_amount),
                amount_log:Number(order.order_amount) ,
                note: `${order.user_id} 通过[${await this.model('pingxx').where({id: order.payment}).getField('title', true)}]支付方式进行充值,订单编号：${order.order_no}`
              };
              await this.model('balance_log').add(log);
          }
          // 记录支付日志
          await this.model('doc_receiving').where({order_id: order.id}).update({pay_status: 1, payment_time: (time_paid)});
         }
        }
        console.log('app端支付回调code--9:'+code.orderid);
        if (order.pay_status == 0&& order.type == 1) {
            await this.model('order').where({order_no: order.order_no}).delete();
        }
        console.log('app端支付code.opstate--:'+code.returncode);
        //return this.body = 'opstate=0';
		return this.body = 'OK';
      }else{
        let notify_remark =(code.returncode==-1?"请求参数无效":"签名错误");
        await this.model('order').where({order_no:code.orderid}).update({status:4,pay_status:-1,notify_remark:notify_remark,pay_time:time_paid,completion_time:completiontime,pingxx_id:code.transaction_id});
        // 记录支付日志
        await this.model('doc_receiving').where({order_id: order.id}).update({pay_status:-1, payment_time: (time_paid)});
         
        return this.body = 'NO';
       }
      }else{  //attach end
        console.log('app端支付code.attach--错误!');
        return this.body = 'NO';
      }
    }else{ //order end
       console.log('app端支付code.orderid--错误!');
       return this.body = 'NO';
    }
  }
  
  // APP端支付页面跳转地址
  //http://www.hongshihuyu.com/pay/result/022018093006908aba88
  async resultAction() {
    const code = this.post();
    console.log('app端支付页面跳转 code--:'+JSON.stringify(code));
    const orderid = this.get('orderid') || 0;
	console.log('result orderid-----------:'+orderid);
    //code.orderid = orderid;
    console.log('APP支付 支付页面跳转地址 code--:'+code);
    // 支付回掉
    if (code.orderid) {
      const order = await this.model('order').where({order_no:code.orderid}).find();
      this.assign('order', order);
    } 
    this.meta_title = '支付结果';// 标题1
    // 判断浏览客户端
    if (this.isMobile) {
      return this.display(this.mtpl());
    } else {
      return this.display();
    }
  }
};
